Application Development 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: 

bdc-issue

Former Member
0 Kudos

Hi Experts,

Can u plz check the below code. It's working fine but the file is not getting created.

*&---------------------------------------------------------------------*
*& Report  Z13M_EXTRACT_ZFIELDS                                        *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  z13m_extract_zfields.

* *** Variables
DATA: g_f_verz    TYPE string,
      g_f_tdname  TYPE stxh-tdname,
      g_f_ersda   TYPE mara-ersda,
      g_f_laeda   TYPE mara-laeda.

DATA: BEGIN OF g_t_marc OCCURS 0,
        matnr   LIKE marc-matnr,
        werks   LIKE marc-werks,
        zz1nb   LIKE marc-zz1nb,
        zz2nb   LIKE marc-zz2nb,
        zzezg   LIKE marc-zzezg,
        zzfhw   LIKE marc-zzfhw,
        zzkzdkz LIKE marc-zzkzdkz,
        zzwrt   LIKE marc-zzwrt,
        zzbcd   LIKE mara-zzbcd,
        zzers   LIKE mara-zzers,
      END OF g_t_marc.

DATA: rec(200) TYPE c.
DATA: tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.


PARAMETERS:     p_werks TYPE marc-werks
                        OBLIGATORY
                        DEFAULT 9700.
*                p_vkorg TYPE mvke-vkorg
*                        OBLIGATORY
*                        DEFAULT 9701.
*SELECT-OPTIONS: s_ersda FOR g_f_ersda,
*                s_laeda FOR g_f_laeda.
PARAMETERS:     p_pfad  TYPE rlgrap-filename
                        OBLIGATORY
                        DEFAULT '\\FS000P01\DPA\IN\C006\',
                p_datn  TYPE c LENGTH 24
                        LOWER CASE
                        OBLIGATORY.

* *** Create file name for selection screen
INITIALIZATION.
  CONCATENATE 'Extract_'
              sy-datum
              INTO p_datn.

* *** Validation
AT SELECTION-SCREEN ON
                    VALUE-REQUEST FOR p_pfad.
  GET CURSOR FIELD p_pfad VALUE p_pfad.
  g_f_verz = p_pfad.
* Search directory
  PERFORM fileselect
          CHANGING g_f_verz.
  p_pfad = g_f_verz.

* *** Processing
START-OF-SELECTION.

  PERFORM marc_mara_extract.
  PERFORM download.



*&---------------------------------------------------------------------*
*&      Form  fileselect
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fileselect
     CHANGING ch_f_verz TYPE string.

  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    IMPORTING
      serverfile       = ch_f_verz
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.

  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " FILESELECT
*&---------------------------------------------------------------------*
*&      Form  marc_mara_extract
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM marc_mara_extract .

  SELECT a~matnr a~werks a~zz1nb a~zz2nb
         a~zzezg a~zzfhw a~zzkzdkz a~zzwrt
         b~zzbcd b~zzers
         FROM marc AS a INNER JOIN mara AS b ON a~matnr = b~matnr
         INTO CORRESPONDING FIELDS OF TABLE g_t_marc
         WHERE a~werks = p_werks.
*                     AND   ersda IN s_ersda
*                     AND   laeda IN s_laeda.


ENDFORM.                    " marc_mara_extract
*&---------------------------------------------------------------------*
*&      Form  download
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM download .

  DATA: l_f_filename TYPE string,
         wa_message  TYPE string.

  CONCATENATE p_pfad p_datn INTO l_f_filename.

  OPEN DATASET l_f_filename FOR OUTPUT IN TEXT MODE
                          ENCODING DEFAULT
                          MESSAGE wa_message.

  IF sy-subrc IS NOT INITIAL.
*    p_l_subrc = sy-subrc.
    WRITE: / 'Error during download of data:'(001),
             l_f_filename,
             wa_message.
    EXIT.
  ELSE.
    LOOP AT g_t_marc.
      CONCATENATE g_t_marc-matnr g_t_marc-werks
                  g_t_marc-zz1nb g_t_marc-zz2nb
                  g_t_marc-zzezg g_t_marc-zzfhw
                  g_t_marc-zzkzdkz g_t_marc-zz2nb
                  g_t_marc-zzwrt  g_t_marc-zzbcd
                  g_t_marc-zzers
                  INTO rec SEPARATED BY tab.
      TRANSFER rec TO l_f_filename.
    ENDLOOP.
    IF sy-subrc EQ 0.
      WRITE: / 'Data sucessfully downloaded:'(003),
               'Location:'(004),
                l_f_filename.
    ENDIF.

  ENDIF.

  CLOSE DATASET l_f_filename.

ENDFORM.                    " download

1 ACCEPTED SOLUTION

former_member585060
Active Contributor
0 Kudos

Hi,

In your code

IF sy-subrc IS NOT INITIAL.

  • p_l_subrc = sy-subrc.

WRITE: / 'Error during download of data:'(001),

l_f_filename,

wa_message.

EXIT.

Modify the code as

IF sy-subrc NE 0.

WRITE: / 'Error during download of data:'(001),

l_f_filename,

wa_message.

EXIT.

Also check in the Debugging wether your Internal Table g_t_marc is having data or not?

Regards

Bala Krishna

Edited by: Bala Krishna on Oct 17, 2008 11:49 AM

2 REPLIES 2

Former Member
0 Kudos

While executing it it's showing that file is successfully downloaded. but it's not getting created.

Can anyone plz post the solution for this.

former_member585060
Active Contributor
0 Kudos

Hi,

In your code

IF sy-subrc IS NOT INITIAL.

  • p_l_subrc = sy-subrc.

WRITE: / 'Error during download of data:'(001),

l_f_filename,

wa_message.

EXIT.

Modify the code as

IF sy-subrc NE 0.

WRITE: / 'Error during download of data:'(001),

l_f_filename,

wa_message.

EXIT.

Also check in the Debugging wether your Internal Table g_t_marc is having data or not?

Regards

Bala Krishna

Edited by: Bala Krishna on Oct 17, 2008 11:49 AM