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

how to write data to table

1190_5939_439
Active Participant
0 Likes
6,251

I don't write data to table . And the table is created by me .Can you help me ?

The code is following:

  LOOP AT lt_dz INTO wa_dz.    
SELECT SINGLE maktx INTO wa_dz-maktx
      FROM makt WHERE matnr = wa_dz-matnr AND spras = sy-langu.
    SHIFT wa_dz-matnr LEFT DELETING LEADING '0'.
    "IF sy-tcode = 'ZRMM009' AND wa_h-zbsat = 'C'.
     "wa_dz-ssmng = wa_dz-bdmng.
 IF  wa_h-zbsat = 'S'.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_dz-ssmng
        IMPORTING
          output = wa_dz-ssmng.
    UPDATE ztpsmx SET SSMNG = wa_dz-ssmng " I only write data to table by it.
          WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr.
    ENDIF.
    MODIFY lt_dz FROM wa_dz TRANSPORTING matnr maktx ssmng.
  ENDLOOP.


1 ACCEPTED SOLUTION
Read only

1190_5939_439
Active Participant
0 Likes
6,137

I find the answer. I put the code in error position.

LOOP AT lt_dz INTO wa_dz WHERE ssmng > 0 AND zuart = 'PE'.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_dz-matnr
        IMPORTING
          output = wa_dz-matnr.


      gmitem-material = wa_dz-matnr.
      gmitem-plant    = wa_dz-werks.              "工厂
      gmitem-stge_loc = wa_dz-lgfsb.              "发出库存地
      gmitem-move_type  = '411'.                  "移动类型


      gmitem-move_plant = wa_dz-werks.
      gmitem-move_stloc = wa_dz-lgort.            "接收库存地
      gmitem-entry_qnt  = wa_dz-ssmng.            "实收数量
         UPDATE ztpsmx SET  SSMNG = wa_dz-ssmng                           WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr." I put it  here.
      CONCATENATE wa_dz-zbanz '/' wa_dz-zgwei INTO gmitem-item_text.      "班组/工位
      APPEND gmitem.
      CLEAR gmitem.
*序列号
      IF wa_dz-zzvin IS NOT INITIAL.
        gmserial-matdoc_itm = l_zeile.
        gmserial-serialno   = wa_dz-zzvin.
        APPEND gmserial.
        l_zeile = l_zeile + 1.
      ENDIF.
*
    ENDLOOP.


I don't write data to table . And the table is created by me .Can you help me ?

The code is following:

  LOOP AT lt_dz INTO wa_dz.    
SELECT SINGLE maktx INTO wa_dz-maktx
      FROM makt WHERE matnr = wa_dz-matnr AND spras = sy-langu.
    SHIFT wa_dz-matnr LEFT DELETING LEADING '0'.
    "IF sy-tcode = 'ZRMM009' AND wa_h-zbsat = 'C'.
     "wa_dz-ssmng = wa_dz-bdmng.
 IF  wa_h-zbsat = 'S'.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_dz-ssmng
        IMPORTING
          output = wa_dz-ssmng.
    UPDATE ztpsmx SET SSMNG = wa_dz-ssmng " I only write data to table by it.
          WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr.
    ENDIF.
    MODIFY lt_dz FROM wa_dz TRANSPORTING matnr maktx ssmng.
  ENDLOOP.


17 REPLIES 17
Read only

Sandra_Rossi
Active Contributor
0 Likes
6,137

What did you conclude from your debug?

Read only

Sandra_Rossi
Active Contributor
0 Likes
6,137

By the way, not related to your question, but SSMNG is a numeric field, it's incorrect to use CONVERSION_EXIT_ALPHA_INPUT.

Read only

1190_5939_439
Active Participant
0 Likes
6,137

To Sandra

I don't write data to table by program.

Read only

6,137

Please use the COMMENT button for comments, questions, adding details, replying to OP comment, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

If you want to target someone, if this person has posted an Answer, use the button COMMENT, if this person is the Original Poster of the question he/she will be automatically informed, otherwise copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work/but typing this character will suggest hyperlinked names).

Read only

6,137

Thanks. I understand how to add comment.

Read only

Abinathsiva
Active Contributor
6,137

Hi 1190_5939_439

Check the MATNR data in Ztable

 LOOP AT lt_dz INTO wa_dz.    
SELECT SINGLE maktx INTO wa_dz-maktx
      FROM makt WHERE matnr = wa_dz-matnr AND spras = sy-langu.

    SHIFT wa_dz-matnr LEFT DELETING LEADING '0'. "Check this how it's captured in ZTable.

 IF  wa_h-zbsat = 'S'.
    UPDATE ztpsmx SET SSMNG = wa_dz-ssmng 
       WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr.
 ENDIF.
    MODIFY lt_dz FROM wa_dz TRANSPORTING matnr maktx ssmng.
  ENDLOOP.
Read only

0 Likes
6,136

Hi abishankar

Can you tell me how to check the MATNR data in Ztable? when I delete "SHIFT wa_dz-matnr LEFTDELETINGLEADING'0'". the result is the same. I don't understand the code.

Read only

0 Likes
6,136

Hi, Directly try by

Modify Ztable from table internaltable.

Read only

0 Likes
6,136

Is it right ?

 LOOP AT lt_dz INTO wa_dz.
    SELECT SINGLE maktx INTO wa_dz-maktx
      FROM makt WHERE matnr = wa_dz-matnr AND spras = sy-langu.
  "  SHIFT wa_dz-matnr LEFT DELETING LEADING '0'.
    "IF sy-tcode = 'ZRMM009' AND wa_h-zbsat = 'C'.
     "wa_dz-ssmng = wa_dz-bdmng.
   IF  wa_h-zbsat = 'S'.
     MODIFY ztpsmx  from lt_dz.   " I add it .
    "UPDATE ztpsmx SET SSMNG = wa_dz-ssmng "zeile = l_zeile
        "  WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr.
    ENDIF.
    MODIFY lt_dz FROM wa_dz TRANSPORTING matnr maktx ssmng.
  ENDLOOP.


Read only

0 Likes
6,136

the data is NOT still written in the ztable.

Read only

Sandra_Rossi
Active Contributor
0 Likes
6,136

If the UPDATE sets sy-subrc <> 0, no data is updated because there is no line corresponding to the WHERE condition. To know why the column values of ZTPSMX don't correspond to the values in the WHERE condition, write a temporary program with a SELECT and change the WHERE condition until a line is found, and you'll understand your error.

Read only

1190_5939_439
Active Participant
0 Likes
6,136

When I write a temporary program. And I give var to value. In the ztable , SSMNG is chaged. The code is following :

REPORT ZJGLTEST.
DATA:l_zpsdh     LIKE ztpsmx-zpsdh,               
     wa_h        LIKE ztpsmx,
     l_bldat     LIKE mkpf-bldat,                 
     l_budat     LIKE mkpf-budat,                 
     l_lgfse     LIKE t001l-lgobe,                
     l_lgobe     LIKE t001l-lgobe,                
     l_name2     LIKE t001w-name1,                
     l_zbsat(12).
DATA: BEGIN OF lt_dz OCCURS 0.
        INCLUDE STRUCTURE ztpsmx.
DATA:   maktx    LIKE makt-maktx,
        posar(1),
        END OF lt_dz.
DATA:wa_dz LIKE lt_dz.
DATA: MAT_DOC TYPE MBLNR,
      mat_gjahr TYPE gjahr.

UPDATE ztpsmx SET SSMNG = '1'
 WHERE  zpsdh = 'PE2008100008' AND zgwei = 'UB40' AND matnr = '85101200FNAA2000'.

Read only

1190_5939_439
Active Participant
6,136

HI sandra.rossi

what is the" line corresponding"?

Read only

1190_5939_439
Active Participant
0 Likes
6,136

HI sandra.rossi

Thanks. I will do it as what you said.

Read only

Sandra_Rossi
Active Contributor
6,136

For instance, write a temporary program with this kind of SELECT to understand why no line is found by doing a wider search (test SY-DBCNT or SY-SUBRC at each SELECT to know if something is found or not):

DATA itab TYPE TABLE OF ztpsmx.
SELECT * FROM ztpsmx WHERE zpsdh = 'PE2008100008' AND zgwei = 'UB40' AND matnr = '85101200FNAA2000' INTO TABLE itab.
SELECT COUNT(*) FROM ztpsmx WHERE zpsdh = 'PE2008100008' INTO TABLE itab.
SELECT COUNT(*) FROM ztpsmx WHERE zpsdh = 'PE2008100008' AND zgwei = 'UB40' INTO TABLE itab.
SELECT COUNT(*) FROM ztpsmx WHERE matnr = '85101200FNAA2000' INTO TABLE itab.
SELECT COUNT(*) FROM ztpsmx WHERE matnr LIKE '85101200F%' INTO TABLE itab.
SELECT COUNT(*) FROM ztpsmx WHERE matnr LIKE '%85101200F%' INTO TABLE itab.

etc.

Read only

1190_5939_439
Active Participant
0 Likes
6,136

The error is here when I use your code and change your code.

Read only

1190_5939_439
Active Participant
0 Likes
6,138

I find the answer. I put the code in error position.

LOOP AT lt_dz INTO wa_dz WHERE ssmng > 0 AND zuart = 'PE'.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_dz-matnr
        IMPORTING
          output = wa_dz-matnr.


      gmitem-material = wa_dz-matnr.
      gmitem-plant    = wa_dz-werks.              "工厂
      gmitem-stge_loc = wa_dz-lgfsb.              "发出库存地
      gmitem-move_type  = '411'.                  "移动类型


      gmitem-move_plant = wa_dz-werks.
      gmitem-move_stloc = wa_dz-lgort.            "接收库存地
      gmitem-entry_qnt  = wa_dz-ssmng.            "实收数量
         UPDATE ztpsmx SET  SSMNG = wa_dz-ssmng                           WHERE zpsdh = l_zpsdh AND zgwei = wa_dz-zgwei AND matnr = wa_dz-matnr." I put it  here.
      CONCATENATE wa_dz-zbanz '/' wa_dz-zgwei INTO gmitem-item_text.      "班组/工位
      APPEND gmitem.
      CLEAR gmitem.
*序列号
      IF wa_dz-zzvin IS NOT INITIAL.
        gmserial-matdoc_itm = l_zeile.
        gmserial-serialno   = wa_dz-zzvin.
        APPEND gmserial.
        l_zeile = l_zeile + 1.
      ENDIF.
*
    ENDLOOP.