Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Maintenance View issues with an ABAP program

Former Member
0 Likes
3,006

Hi,

I need to update a Maintenance view(V_JURIC) from a txt file. I created an ABAP module to do this and when I update the tables that compose the view(TABLE_A and TABLE_B), the view is not completely getting updated in the last field. Any suggestions? Here is sample of the code:

REPORT zbr_loc_mast_data_1 MESSAGE-ID fb.

TABLES: j_1btxjurt,
        j_1btxjur.

DATA wa_j_1btxjurv TYPE j_1btxjurv.

DATA wa_j_1btxjurt TYPE j_1btxjurt.

DATA wa_j_1btxjur TYPE j_1btxjur.

DATA: BEGIN OF i_j_1btxjurt OCCURS 2000.
        INCLUDE STRUCTURE j_1btxjurt.
DATA: END OF i_j_1btxjurt.

DATA: i_j_1btxjurv LIKE j_1btxjurv OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF rec OCCURS 0,
      tbl_name(10)     TYPE c,        " Table name(Constant 'J_1BTXJURV')
      field_2(1)       TYPE c,        " Constant "X"
      jur_code(10)     TYPE c,        " Jurisdiction code
      municip(60)      TYPE c,        " Municipality Name
END OF rec.

DATA: w_num_recs TYPE i.
      
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: in_file TYPE localfile OBLIGATORY
            DEFAULT 'C:\lista de municipios.txt'.
SELECTION-SCREEN END OF BLOCK block1.


START-OF-SELECTION.
  PERFORM read_file.
  IF sy-subrc = 0.
    PERFORM update_table.
  ENDIF.

END-OF-SELECTION.

*Summary

    WRITE: / 'Number of records read: ' COLOR COL_TOTAL INVERSE OFF INTENSIFIED ON,
         32 w_num_recs COLOR COL_POSITIVE INVERSE OFF
            INTENSIFIED ON.

  

*----------------------------------------------------------------------*
*       Form  read_file
*----------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM read_file.

  DATA: l_filename TYPE string.

  MOVE in_file TO l_filename.


  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = l_filename
      filetype                = 'DAT'
*      HAS_FIELD_SEPARATOR     = SPACE
*      HEADER_LENGTH           = 0
*      READ_BY_LINE            = 'X'
*      DAT_MODE                = SPACE
*      CODEPAGE                = SPACE
*      IGNORE_CERR             = ABAP_TRUE
*      REPLACEMENT             = '#'
*      VIRUS_SCAN_PROFILE      =
*    IMPORTING
*      FILELENGTH              =
*      HEADER                  =
    CHANGING
      data_tab                = rec[]
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      not_supported_by_gui    = 17
      error_no_gui            = 18
      OTHERS                  = 19.
  .
  IF sy-subrc <> 0.
    MESSAGE e039 WITH in_file.
  ENDIF.

ENDFORM.                    " read_file

*----------------------------------------------------------------------*
*       Form  update_table
*----------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM update_table.

  CLEAR: w_num_recs,
         w_num_recs_btable,
         w_num_recs_atable,
         w_num_recs_inserted.


    LOOP AT rec.

    w_num_recs = w_num_recs + 1.

    MOVE 'BR'          TO wa_j_1btxjur-country.
    MOVE rec-jur_code  TO wa_j_1btxjur-taxjurcode.
    MOVE 'PT'          TO wa_j_1btxjurt-spras.
    MOVE 'BR'          TO wa_j_1btxjurt-country.
    MOVE rec-jur_code  TO wa_j_1btxjurt-taxjurcode.
    MOVE rec-municip   TO wa_j_1btxjurt-text.

    
    INSERT into j_1btxjurt values wa_j_1btxjurt.

    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.

    INSERT into j_1btxjur values wa_j_1btxjur.

    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.

  ENDLOOP.

  
  ENDFORM.                    " update_table

Edited by: Thomas Zloch on Nov 5, 2010 9:24 AM - please use code tags

1 ACCEPTED SOLUTION
Read only

GauthamV
Active Contributor
0 Likes
2,627

Insert statement will only create new records in the table.

Use Modify statement to create and update records in table.

Sorry, I tried using the update statement as follow: UPDATE j_1btxjurt FROM wa_j_1btxjurt.

and it is not inserting any records since it is getting a RC of 4..

10 REPLIES 10
Read only

GauthamV
Active Contributor
0 Likes
2,628

Insert statement will only create new records in the table.

Use Modify statement to create and update records in table.

Read only

Former Member
0 Likes
2,627

Sorry, I tried using the update statement as follow: UPDATE j_1btxjurt FROM wa_j_1btxjurt.

and it is not inserting any records since it is getting a RC of 4..

Read only

Former Member
0 Likes
2,627

That's why Gautham mentioned MODIFY. With that statement a record either gets inserted or updated.

Read only

Former Member
0 Likes
2,627

OK, I used the MODIFY statement and it is inserting the records, but the last field in the view j_1btxjurv-text is blank. The corresponding table field j_1btxjurt-text is populated with the text characters. Any ideas on what else it can be?

Read only

Former Member
0 Likes
2,627

Well, you don't have any error handling after the first insert. What is sy-subrc after the first insert?

Rob

Read only

Former Member
0 Likes
2,627

The return code is 0 and the sy-dbcnt is 1...

Read only

Former Member
0 Likes
2,627

Both tables J_1BTXJUR and J_1BTXJURT have records? And.. maybe a bit daft to ask: is your logon language the same as the SPRAS in J_1BTXJURT?

Read only

Former Member
0 Likes
2,627

OK - so it doesn't appear in the view. Do the values appear in the underlying table (j_1btxjurt )?

Rob

Read only

Former Member
0 Likes
2,627

Ahhhh, that was the problem.. I was logged in EN and the records are inserted in PT for portugues.. The problem is fixed.. Thanks for the help, the brain is getting old..

Read only

Former Member
0 Likes
2,627
MOVE 'PT'          TO wa_j_1btxjurt-spras.

maybe change that to:

MOVE 'P'          TO wa_j_1btxjurt-spras.