RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Moving to arrays in free format Print E-mail
User Rating: / 1
Written by Chamara Withanachchi   
Moving to arrays in free format

I was moving valirble values to arrays using following methoud.

     D MyVariable      S             35A
     D MyArray         S              1A   Dim(35)
     D i               S              2  0


        MyVariable = 'Move Array in Free Format';

        For i=1 to %Len(MyVariable);
          MyArray(i) = %SubSt(MyVariable : i : 1);

        *INLR = *ON;


But later in Bob Cozzi's RPG tip I found a excellent methoud with memcpy C API


     D MyVariable      S             40A
     D MyArray         S              1A   Dim(35)

     D MemCpy          PR                  ExtProc('__memcpy')
     D  Target                         *   Value
     D  Source                         *   Value
     D  Lenght                       10U 0 Value


        MyVariable = 'Move Array in Free Format - This is Grate';

        MemCpy(%Addr(MyArray) :
               %Addr(MyVariable) :

        *INLR = *ON;


Also You can wrap the array in a DS and move the array to variable or variable to array

   D arrDs           DS                                    
   D  Arr                           1    Dim(30)           
   DVar              S             30                      
        var = 'Test Data to Array';                        
        arrDS = var;                                       
        arr(6) = ' ';                                      
        var = arrDS;                                       
        *inLR = *On;                                       
<Previous   Next>