Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Can i create a new record into nast by abap code ?

I have this code to call a nast to print purchase order into forlder system by PDF:

FUNCTION zme_pdf.
*"----------------------------------------------------------------------
*"*"Interfaccia locale:
*"  IMPORTING
*"     VALUE(EBELN) LIKE  EKKO-EBELN
*"     VALUE(KAPPL) LIKE  NASE-KAPPL DEFAULT 'EF'
*"     VALUE(KSCHL) LIKE  NASE-KSCHL DEFAULT 'ZPDF'
*"     VALUE(NACHA) LIKE  MSG0-NACHA DEFAULT '8'
*"     VALUE(MODE) TYPE  NA_VERMO DEFAULT '1'
*"  EXPORTING
*"     VALUE(MESSAGE) LIKE  BAPIRET2-MESSAGE
*"  EXCEPTIONS
*"      ODA_NOT_FOUND
*"      MESSAGE_NOT_FOUND
*"----------------------------------------------------------------------

* check oda
  SELECT SINGLE * FROM ekko WHERE ebeln = ebeln.
  IF sy-subrc NE 0.
    RAISE oda_not_found.
  ENDIF.

*  write: ebeln TO l_objky.
  l_objky = ebeln.
  SELECT SINGLE * FROM nast WHERE kappl = kappl
                              AND kschl = kschl
                              AND objky = l_objky
                              AND nacha = nacha.
  IF sy-subrc NE 0.
    RAISE message_not_found.
  ENDIF.
* Run output type
  refresh: ri_medium,
           ri_object,
           ri_type,
           ri_application.

  ri_medium-sign = 'I'.
  ri_medium-option = 'EQ'.
  ri_medium-low = nacha.
  APPEND ri_medium.

  ri_type-sign = 'I'.
  ri_type-option = 'EQ'.
  ri_type-low = kschl.
  APPEND ri_type.

  ri_object-sign = 'I'.
  ri_object-option = 'EQ'.
  ri_object-low = l_objky.
  APPEND ri_object.

  ri_application-sign = 'I'.
  ri_application-option = 'EQ'.
  ri_application-low = kappl.
  APPEND ri_application.

  REFRESH gt_msg.

  CALL FUNCTION 'WFMC_MESSAGES_SELECT'
    EXPORTING
      pi_processing  = mode
      pi_printer     = l_print
    TABLES
      ri_medium      = ri_medium
      ri_type        = ri_type
      ri_object      = ri_object
      ri_application = ri_application
      tx_messages    = gt_msg.

  LOOP AT gt_msg INTO g_msg.
* set table index
    g_msg-tabix = sy-tabix.
    MODIFY gt_msg FROM g_msg.
    CLEAR g_disp.
* build GT_DISP table from GT_MSG
    IF mode EQ c_process_initial.
* initial processing
      MOVE-CORRESPONDING g_msg TO g_disp1.
      APPEND g_disp1 TO gt_disp1.
    ELSE.
* repeated or error processing
      MOVE-CORRESPONDING g_msg TO g_disp.
      APPEND g_disp TO gt_disp.
    ENDIF.
  ENDLOOP.

*  IF p_dialog EQ 'X'.
*    p_dialog = space.
*  ENDIF.
  p_dialog = 'X'.

  IF mode EQ c_process_initial.
* use display structure without processing date
    CALL FUNCTION 'WFMC_MESSAGES_PROCESS'
         EXPORTING
              pi_display_id = 'NALIGENERIC_1st'
              pi_no_dialog  = p_dialog
              pi_vermo      = mode
*         PI_NO_COMMIT  = ' '
*         PI_NO_ENQUEUE = ' '
              pi_use_grid_control = p_grid
         TABLES
              tx_messages   = gt_msg
              tx_display    = gt_disp1
              .
  ELSE.
* use display structure that includes processing date
    CALL FUNCTION 'WFMC_MESSAGES_PROCESS'
         EXPORTING
              pi_display_id = 'NALIGENERIC'
              pi_no_dialog  = p_dialog
              pi_vermo      = mode
*         PI_NO_COMMIT  = ' '
*         PI_NO_ENQUEUE = ' '
              pi_use_grid_control = p_grid
         TABLES
              tx_messages   = gt_msg
              tx_display    = gt_disp
              .
  ENDIF.

  CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'
    EXPORTING
      id         = sy-msgid
      number     = sy-msgno
      language   = sy-langu
      textformat = 'ASC'
    IMPORTING
      message    = message.

ENDFUNCTION.

It is possible if:

SELECT SINGLE * FROM nast WHERE kappl = kappl

AND kschl = kschl

AND objky = l_objky

AND nacha = nacha.

IF sy-subrc NE 0.

RAISE message_not_found.

ENDIF.

If i not found a nast record (messege to print pdf order) Can I create a new record to print purchase order by code ?

Former Member
Not what you were looking for? View more on this topic or Ask a question