Inserting records from 1 to 99 in a file

2640 pts.
Tags:
SQLRPGLE
Hi, How to insert records in a file of 2 field lets say field1 and field2 field1 is constant like 'Name' and field 2 needs to be increased by 1 up to 99. How to write SQLRPGLE program for this?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

any updates please?

Discuss This Question: 12  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • 6r
    May i please know answer of above soon.

    Thanks
    2,640 pointsBadges:
    report
  • philpl1jb
    homework? Show us your code, tell us your problem and we'll help.
    54,090 pointsBadges:
    report
  • 6r

    dou field2=99;
    exec sql
    insert into tableA values('Name',field2);
    field2=field2+1;
    enddo;

    Where :-

    Field1= 10 character
    Field2= 2 Numeric

    After compilation error is
    SQL0206  30   
    Column field2 not in specified tables.

    and if instead of field2, 1 is inserted then it will insert 99 times 1 against Name but not in increasing order.

    Thanks

    2,640 pointsBadges:
    report
  • ToddN2000
    Take a look at the columns in TableA. Is the a column named field2?

    You got an error  "Column field2 not in specified tables."

    I am assuming the incremental field is not named field2 in your TableA.
    133,645 pointsBadges:
    report
  • 6r

    actually instead of field2 if value 1 is inserted like below:-

    eval field2=1;

    dou field2=99;
    exec sql
    insert into tableA values('Name',1);
    field2=field2+1;
    enddo;

    then it will insert 99 times Name in field 1 and '1' in field2.

    But the objective is to get below type results:-

    Field1 Field2

    Name 1

    Name 2

    Name 3

    -......

    ......

    Name 99

    Hope above clarifies problem .


    Thanks

    2,640 pointsBadges:
    report
  • ToddN2000
    Try changing this

    insert into tableA values('Name',1);

    to 
    insert into tableA values('Name',field2);
    133,645 pointsBadges:
    report
  • philpl1jb
    insert into tableA values('Name', :field2);

    Need a ':' to indicate host variable.
    54,090 pointsBadges:
    report
  • 6r

    Tried to write below SQLRPGLE but seems it's not working.

    FTABLEA     UF A E             DISK                          
    DField2         S              2P 0 INZ(1)                
    C                                                           
     /FREE                                                      
          EVAL field2=1;                                        
             DOU field2=99;                                     
             EXEC SQL                                           
                INSERT INTO TABLEA VALUES('NAME',:FIELD2); 
              FIELD2=FIELD2+1;                                   
                ENDDO;                                          
                EVAL *INLR=*ON;                                 
     /END-FREE                                                  
                                                                

    2,640 pointsBadges:
    report
  • 6r
    During debug found that cursor comes on exec sql then to field2=field2+1 means values of field 2 keep on incrementing but nothing gets written in to tableA as per expectation.
    2,640 pointsBadges:
    report
  • philpl1jb

    Odd

    TableA has two fields, first Character at least 4 long

     second numeric at least 2,0.

    .. this program doesn't need the F-spec for TableA


    54,090 pointsBadges:
    report
  • ToddN2000
    When you do a DSPFFD are there 2 fields in your TableA file? What are the field names. Make sure they are of the same data type.
    133,645 pointsBadges:
    report
  • philpl1jb

    After

    /free

    Add this SQL command


       exec sql
           set option commit = *none;

    If the file is journalled sql commitment control will roll back the entries if a COMMIT isn't sent.




                         

    54,090 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: